import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号

#excel_path = 'C:/Users/zlsjNKJS/Desktop/090-2/all.xlsx'
#data = pd.read_excel(excel_path)

csv_path = 'C:/Users/zlsjNKJS/Desktop/090-2/train/train_results.csv'
data = pd.read_csv(csv_path)

'''data['点击率'] = pd.to_numeric(data['点击率'].str.replace('%', ''), errors='coerce') / 100
data['转化率'] = pd.to_numeric(data['转化率'].str.replace('%', ''), errors='coerce') / 100

# 显示转换后的数据的前几行，确认转换正确
print(data[['点击率', '转化率']].head())

print(data.head())

if (data['消耗'] <= 0).any():
    print("ERROR: log transfrom should be positive")
else:
    data['log_消耗'] = np.log1p(data['消耗'])
    print(data[['消耗', 'log_消耗']].head())
    output_path = excel_path
    data.to_excel(output_path, index=False, engine='openpyxl')
    print(f"更新后的数据已保存到{output_path}")'''

desc_stats = data.describe()

print("Data Description:\n", desc_stats)

# 将描述性统计结果保存到Excel文件
output_path = 'C:/Users/zlsjNKJS/Desktop/090-2/data_description_canny.xlsx'
desc_stats.to_excel(output_path, index=True)

print(f"描述性统计结果已保存到 {output_path}")

columns_to_plot = [data.columns[i] for i in [4, 5]]
fig, axes = plt.subplots(nrows=3, ncols=len(columns_to_plot), figsize=(15,12))

for i, columns_name in enumerate(columns_to_plot):
    data.boxplot(column=[columns_name], by=None, ax=axes[0,i])
    axes[0,i].set_title(f'Boxplot of {columns_name}')

    axes[1,i].hist(data[columns_name],bins=20, alpha=0.5)
    axes[1,i].set_title(f'Histogram of {columns_name}')

    data[columns_name].plot(ax=axes[2,i], kind='density', alpha=0.5)
    axes[2,i].set_title(f'Density Plot of{columns_name}')

plt.tight_layout()
plt.show()



